<!DOCTYPE HTML>
<html>
<head>

    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <title></title>
    <style>
        .txt-input {
            border: 1px solid red;
        }
        #p01 {
            width: 300px;
            border: 1px solid blue;
            /* https://www.cnblogs.com/luyingying/p/5144219.html */
            word-wrap: break-word;
            word-break: normal; /* break-all */
        }
    </style>
    <!-- <script type="text/javascript" charset="utf-8" src="../third-party/jquery-1.10.2.min.js"></script> -->
	<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<iframe id="ifr100" style="width:0;height:0;padding:0;margin:0;position:absolute;left;0;top:0;"></iframe>
<p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
<p>中华人民共和国</p>
    <input type="text" id="txt01" /> <input type="button" id="btn01" value="click" /> <input type="button" id="btn02" value="clear" />
<input type="button" id="calc" value="calc" />
    <div id="div01"></div>
    <p id="p01"></p>
    <script type="text/javascript">
		var getEleId = (function(){
			var startId = 100;
			return function(){
				return 'rrk_' + (startId++);
			};
		})();
		
		$(function(){
			var _doc = $('#ifr100')[0].contentWindow.document;
			_doc.open();
			_doc.write('<html><head><title></title>');
			_doc.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>');
			_doc.write( $('style', document)[0].outerHTML );
			_doc.write('</head><body></body></html>');
			_doc.write();
			_doc.close();
		});
		
        $(function () {
            $('#btn02').on('click', function () {
                $('#p01').empty();
            });
            $('#calc').on('click', function () {
                var _h = $('#p01').height();
                var txt = $('#p01').html();
                var len = txt.length;
				var _id = getEleId();
				var innerP = $('<p id="p01">11</p>', $('#ifr100')[0].contentWindow.document);
				innerP.appendTo( $('body', $('#ifr100')[0].contentWindow.document) );
				// var _oneLineHeight = $('#p01', $('#ifr100')[0].contentWindow.document).height();
				var _oneLineHeight = innerP.height();
				innerP.empty();
				var lines = 1, _H = 0, linestr = '', increatStr = '', arr = [];
				var testArr = [];
				for(var i=0;i<len;i++){
					increatStr += txt[i];
					innerP.html( increatStr );
					_H = innerP.height();
					if( _H > lines*_oneLineHeight ){
						lines = lines + 1;
						arr.push( linestr );
						linestr = '';
					}
					linestr += txt[i];
				}
				if(linestr.length > 0){
					arr.push( linestr );
				}
				console.log( arr.length, arr );
				
				// $('body', $('#ifr100')[0].contentWindow.document).append();
				// console.log( $('#ifr100').height() );
                // console.log( $('#ifr100')[0].contentWindow.document );
            });
            $('#btn01').on('click', function () {
                if( $.trim( $('#txt01').val() ) == '' ){
                    $('#txt01').addClass('txt-input');
                    return false;
                }else{
                    $('#txt01').removeClass('txt-input');
                }
                var val = $.trim($('#p01').html());
                if( val == '' ){
                    $('#p01').html( $('#txt01').val() );
                }else{
                    var _old = $('#p01').html();
                    $('#p01').html( _old + $('#txt01').val() );
                }
            });
        });
    </script>

</body>


</html>
